﻿package mortal.game.view.lotteryDraw
{
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.ui.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.firstReCharge.*;
    import mortal.game.view.rebate.data.*;
    import mortal.mvc.core.*;

    public class lotteryDrawPlayView extends GSprite
    {
        private var _showItemList:Vector.<lotteryDrawShowItem>;
        private var _specialBlock:GImageBitmap;
        private var _modaiBtn:GLoadingButton;
        private var _rechargeBtn:GLoadingButton;
        private var _playBtn1:GLoadingButton;
        private var _playBtn2:GLoadingButton;
        private var _playBtn3:GLoadingButton;
        private var _costKeyTxt:GTextFiled;
        private var _costKeyTxt1:GTextFiled;
        private var _diamondNumTxt:GTextFiled;
        private var _keyTxt:GTextFiled;
        private var _keyNumTxt:GTextFiled;
        private var _diamondPoolBmpTxt:BitmapNumberText;
        private var _diamondPoolItem:BaseItem;
        private var _equipItem:BaseItem;
        private var _skillItem:BaseItem;
        private var _level:int = -1;
        private var _keyID:int = -1;
        private var _test:GTextFiled;
        private var eff:lotteryDrawFlyEffect;
        private var _coinCumBox:GConsumeBox;
        private var _coinType:int;
        private var _coinLabel:String;

        public function lotteryDrawPlayView()
        {
            this.eff = new lotteryDrawFlyEffect();
            return;
        }// end function

        public function set panelData(param1:Object) : void
        {
            this._level = int(param1.level);
            this._keyID = int(param1.keyID);
            this._coinType = int(param1.coinType);
            this._coinLabel = String(param1.coinLabel);
            if (this._keyTxt)
            {
                this._keyTxt.text = Language.getStringByParam(90434, String(param1.keyName));
            }
            if (this._costKeyTxt)
            {
                this._costKeyTxt.text = Language.getStringByParam(90435, String(param1.keyName));
            }
            if (this._costKeyTxt1)
            {
                this._costKeyTxt1.text = Language.getStringByParam(90436, String(param1.keyName));
            }
            if (this._specialBlock)
            {
                this._specialBlock.imgUrl = String(param1.splBlockUrl);
            }
            this.setItemShow();
            this.setKeyNum();
            var _loc_2:* = Cache.instance.pack.lotteryDrawBag.itemLength > 0 ? (true) : (false);
            Cache.instance.lotteryDraw.isModaiEffect = _loc_2;
            this.playEffect(_loc_2);
            if (this._coinCumBox)
            {
                this._coinCumBox.dispose();
                this._coinCumBox = null;
            }
            this._coinCumBox = UIFactory.gConsumeBox("", 250 + 115 + 30, 580 - 2, 0, this);
            this._coinCumBox.addItem(ConsumeData.ShowMoneyType, this._coinType, 0, this._coinLabel + ":");
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.lotteryDrawBg, 10, 60, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.lotteryDrawTopBg, 10, 60, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.lotteryDrawDiamodBlock, 175 + 40 + 11, 140 + 30, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.lotteryDrawEquipBlock, 145 + 20 + 11, 224 + 60, this));
            this._specialBlock = UIFactory.gImageBitmap("", 275 + 60 + 11, 224 + 60, this);
            this._modaiBtn = UIFactory.gLoadingButton(ResFileConst.lotteryDrawPackageBtn, 42, 573, 82, 29, this);
            this._rechargeBtn = UIFactory.gLoadingButton(ResFileConst.lotteryDrawRechargeBtn, 545, 573, 82, 29, this);
            this._playBtn1 = UIFactory.gLoadingButton(ResFileConst.lotteryDrawPlayPlayBtn, 118 - 5, 520, 134, 50, this);
            this._playBtn2 = UIFactory.gLoadingButton(ResFileConst.lotteryDrawPlayPlayBtn, 273 - 5, 520, 134, 50, this);
            this._playBtn3 = UIFactory.gLoadingButton(ResFileConst.lotteryDrawPlayPlayBtn, 428 - 5, 520, 134, 50, this);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.lotteryDrawPlayTxt1, 127, 526, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.lotteryDrawPlayTxt2, 300 - 22, 526, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.lotteryDrawPlayTxt3, 455, 526, this));
            var _loc_1:* = UIFactory.gTextField(Language.getString(90437), 193, 526, 100, 20, this, GlobalStyle.textFormatLv);
            var _loc_2:* = UIFactory.gTextField(Language.getString(90438), 312 + 35, 526, 100, 20, this, GlobalStyle.textFormatLv);
            var _loc_3:* = UIFactory.gTextField(Language.getString(90439), 468, 544, 100, 20, this, GlobalStyle.textFormatLv);
            _loc_1.mouseEnabled = false;
            _loc_2.mouseEnabled = false;
            _loc_3.mouseEnabled = false;
            this.pushUIToDisposeVec(_loc_1);
            this.pushUIToDisposeVec(_loc_2);
            this.pushUIToDisposeVec(_loc_3);
            var _loc_4:* = UIFactory.gTextField(Language.getString(90448), 232 - 106, 578, 100, 20, this, GlobalStyle.textFormatBai);
            _loc_4.mouseEnabled = false;
            this.pushUIToDisposeVec(_loc_4);
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.Yuanbao, 342 - 106, 576, this));
            this._diamondPoolBmpTxt = UIFactory.bitmapNumberText(15 + 315, 27 + 213, "PetGrowYellowNum.png", 18, 21, -2, this, 9);
            this._diamondPoolBmpTxt.mouseEnabled = false;
            this._costKeyTxt = UIFactory.gTextField("", 131, 544, 100, 20, this, GlobalStyle.textFormatLv);
            this._costKeyTxt.mouseEnabled = false;
            this._costKeyTxt1 = UIFactory.gTextField("", 251 + 33, 544, 100, 20, this, GlobalStyle.textFormatLv);
            this._costKeyTxt1.mouseEnabled = false;
            this._diamondNumTxt = UIFactory.gTextField("", 142 - 106, 578, 200, 20, this, GlobalStyle.textFormatHuang2.right());
            this._diamondNumTxt.mouseEnabled = false;
            this._diamondNumTxt.htmlText = MoneyUtil.getFormatInt(Cache.instance.role.money.gold);
            this._keyTxt = UIFactory.gTextField("", 370 - 80, 578, 100, 20, this, GlobalStyle.textFormatBai);
            this._keyNumTxt = UIFactory.gTextField("", 280 - 80, 578, 200, 20, this, GlobalStyle.textFormatHuang2.right());
            this._diamondPoolItem = UICompomentPool.getUICompoment(EffectItem);
            this._diamondPoolItem.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            this._diamondPoolItem.x = 100 + 146;
            this._diamondPoolItem.y = 100 + 113;
            this._diamondPoolItem.amount = 1;
            this._diamondPoolItem.itemCode = 180011002;
            this._diamondPoolItem.isBind = false;
            this._diamondPoolItem.toolTipData = Language.getString(90440);
            this._diamondPoolItem.showEffect(true, -2, 18, "ArroundEffect_zhi_small.swf");
            this.addChild(this._diamondPoolItem);
            this._equipItem = UICompomentPool.getUICompoment(BaseItem);
            this._equipItem.setItemStyle(ItemStyleConst.Big, ImagesConst.RewardItemBigBg, 4, 4);
            this._equipItem.x = 100 + 109;
            this._equipItem.y = 100 + 229;
            this.addChild(this._equipItem);
            this._skillItem = UICompomentPool.getUICompoment(BaseItem);
            this._skillItem.setItemStyle(ItemStyleConst.Big, ImagesConst.RewardItemBigBg, 4, 4);
            this._skillItem.x = 100 + 279;
            this._skillItem.y = 100 + 229;
            this.addChild(this._skillItem);
            this._showItemList = new Vector.<lotteryDrawShowItem>;
            var _loc_5:int = 0;
            while (_loc_5 < lotteryDrawConst.showItemNum)
            {
                
                this._showItemList[_loc_5] = UICompomentPool.getUICompoment(lotteryDrawShowItem);
                this._showItemList[_loc_5].setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
                this._showItemList[_loc_5].x = lotteryDrawConst.showItemArray1[_loc_5][0] + lotteryDrawConst.startPos.x;
                this._showItemList[_loc_5].y = lotteryDrawConst.showItemArray1[_loc_5][1] + lotteryDrawConst.startPos.y;
                this.addChild(this._showItemList[_loc_5]);
                _loc_5++;
            }
            this._test = UIFactory.gTextField("0", 400 + 50, 278, 200, 20, this);
            if (Global.isDebugModle)
            {
                this._test.visible = true;
            }
            else
            {
                this._test.visible = false;
            }
            this.addListener();
            return;
        }// end function

        private function setItemShow() : void
        {
            var _loc_2:ItemData = null;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:Array = null;
            var _loc_11:Array = null;
            var _loc_12:Array = null;
            var _loc_1:* = Cache.instance.lotteryDraw.getShowItemVec(this._level);
            var _loc_3:* = lotteryDrawConst.targetItemDic;
            if (_loc_1[0])
            {
                _loc_2 = new ItemData(int(_loc_1[0].itemCode));
                this._equipItem.itemData = _loc_2;
                this._equipItem.amount = _loc_1[0].itemAmount;
                if (_loc_2.itemInfo.color >= EColor._EColorOrange)
                {
                    this._equipItem.showEffect(true, 31, 36, "ArriundEffect_zhi_big.swf");
                }
                else
                {
                    this._equipItem.showEffect(false);
                }
            }
            if (_loc_1[1])
            {
                _loc_2 = new ItemData(int(_loc_1[1].itemCode));
                this._skillItem.itemData = _loc_2;
                this._skillItem.amount = _loc_1[1].itemAmount;
                if (_loc_2.itemInfo.color >= EColor._EColorOrange)
                {
                    this._skillItem.showEffect(true, 31, 36, "ArriundEffect_zhi_big.swf");
                }
                else
                {
                    this._skillItem.showEffect(false);
                }
            }
            var _loc_4:* = RebateUtil.getTargetType();
            var _loc_5:Boolean = true;
            var _loc_6:int = 0;
            if (_loc_4 == ETargetType._ETargetTypeNONE)
            {
                _loc_5 = false;
            }
            else
            {
                _loc_6 = _loc_3[_loc_4]["nextTarget"];
            }
            var _loc_7:int = 0;
            while (_loc_7 < lotteryDrawConst.showItemNum)
            {
                
                _loc_8 = 0;
                if (_loc_1[_loc_7 + 2])
                {
                    if (_loc_5)
                    {
                        _loc_8 = 0;
                        _loc_10 = _loc_3[ETargetType._ETargetTypeMountRank]["replaceArr"] as Array;
                        _loc_11 = _loc_3[ETargetType._ETargetTypePetGrowth]["replaceArr"] as Array;
                        _loc_8 = 0;
                        while (_loc_8 < _loc_10.length)
                        {
                            
                            if (int(_loc_1[_loc_7 + 2].itemCode) == int(_loc_10[_loc_8]))
                            {
                                _loc_2 = new ItemData(int(_loc_3[_loc_4]["replaceArr"][_loc_8]));
                                this._showItemList[_loc_7].itemData = _loc_2;
                                break;
                            }
                            else if (int(_loc_1[_loc_7 + 2].itemCode) == int(_loc_11[_loc_8]))
                            {
                                _loc_2 = new ItemData(int(_loc_3[_loc_6]["replaceArr"][_loc_8]));
                                this._showItemList[_loc_7].itemData = _loc_2;
                                break;
                            }
                            else
                            {
                                _loc_2 = new ItemData(int(_loc_1[_loc_7 + 2].itemCode));
                                this._showItemList[_loc_7].itemData = _loc_2;
                            }
                            _loc_8++;
                        }
                    }
                    else
                    {
                        _loc_2 = new ItemData(int(_loc_1[_loc_7 + 2].itemCode));
                        this._showItemList[_loc_7].itemData = _loc_2;
                    }
                    _loc_9 = Cache.instance.role.entityInfo.career;
                    if (_loc_9 != ECareer._ECareerWarrior)
                    {
                        _loc_12 = lotteryDrawConst.anjinPartsDic[ECareer._ECareerWarrior];
                        _loc_8 = 0;
                        while (_loc_8 < _loc_12.length)
                        {
                            
                            if (int(_loc_1[_loc_7 + 2].itemCode) == int(_loc_12[_loc_8]))
                            {
                                _loc_2 = new ItemData(lotteryDrawConst.anjinPartsDic[_loc_9][_loc_8]);
                                this._showItemList[_loc_7].itemData = _loc_2;
                            }
                            _loc_8++;
                        }
                    }
                    this._showItemList[_loc_7].amount = _loc_1[_loc_7 + 2].itemAmount;
                    if (_loc_2.itemInfo.color >= EColor._EColorOrange)
                    {
                        this._showItemList[_loc_7].showEffect(true, -2, 18, "ArroundEffect_zhi_small.swf");
                    }
                    else
                    {
                        this._showItemList[_loc_7].showEffect(false);
                    }
                }
                _loc_7++;
            }
            return;
        }// end function

        private function onBagUpdate(param1:Object) : void
        {
            this.setKeyNum();
            return;
        }// end function

        public function setKeyNum() : void
        {
            var _loc_1:* = Cache.instance.pack.backPackCache.getItemCountByItemCode(this._keyID, true);
            this._keyNumTxt.text = String(_loc_1);
            return;
        }// end function

        private function onModaiEffectUpdate(event:DataEvent) : void
        {
            var _loc_2:* = Boolean(event.data);
            this.playEffect(_loc_2);
            return;
        }// end function

        private function playEffect(param1:Boolean) : void
        {
            if (this._modaiBtn)
            {
                if (param1)
                {
                    EffectManager.glowFilterReg(this._modaiBtn);
                }
                else
                {
                    EffectManager.glowFilterUnReg(this._modaiBtn);
                }
            }
            return;
        }// end function

        private function addListener() : void
        {
            this._playBtn1.addEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._playBtn2.addEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._playBtn3.addEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._modaiBtn.addEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._rechargeBtn.addEventListener(MouseEvent.CLICK, this.onClickHandle);
            Dispatcher.addEventListener(EventName.LotteryDrawDiamondPoolUpdate, this.updateDiamondPool);
            NetDispatcher.addCmdListener(ServerCommand.MoneyUpdate, this.updateMoney);
            Dispatcher.addEventListener(EventName.LotteryDrawPackageBtnPlayEffect, this.onModaiEffectUpdate);
            Dispatcher.addEventListener(EventName.LotteryDrawRewardFlyToModai, this.onRewardFlyHandle);
            Dispatcher.addEventListener(EventName.LotteryDrawTestPool, this.onLotteryDrawTestPool);
            NetDispatcher.addCmdListener(ServerCommand.NewDayUpdate, this.newDayUpdate);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.onBagUpdate);
            return;
        }// end function

        private function onClickHandle(event:MouseEvent) : void
        {
            if (event.target == this._playBtn1)
            {
                if (this._level == -1)
                {
                    MsgManager.showRollTipsMsg(Language.getString(90441));
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.LotteryDrawPlay, {times:1, level:this._level}));
            }
            else if (event.target == this._playBtn2)
            {
                if (this._level == -1)
                {
                    MsgManager.showRollTipsMsg(Language.getString(90441));
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.LotteryDrawPlay, {times:10, level:this._level}));
            }
            else if (event.target == this._playBtn3)
            {
                if (this._level == -1)
                {
                    MsgManager.showRollTipsMsg(Language.getString(90441));
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.LotteryDrawPlay, {times:50, level:this._level}));
            }
            else if (event.target == this._modaiBtn)
            {
                Dispatcher.dispatchEvent(new Event(EventName.LotteryDrawPackageShow));
            }
            else if (event.target == this._rechargeBtn)
            {
                GameUtil.gotoRecharge(ModuleTypeConst.LotteryWin);
            }
            return;
        }// end function

        private function onRewardFlyHandle(event:DataEvent) : void
        {
            var _loc_5:ItemData = null;
            if (isDisposed)
            {
                return;
            }
            var _loc_2:* = event.data["rewards"] as Array;
            var _loc_3:* = event.data["startPos"] as Point;
            var _loc_4:* = this._modaiBtn.localToGlobal(new Point(18, -10));
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:* = new Array();
            while (_loc_7 < _loc_2.length)
            {
                
                if (_loc_2[_loc_7].type == 0)
                {
                    _loc_8[_loc_7] = new ItemData(int(_loc_2[_loc_7].value));
                }
                else if (_loc_2[_loc_7].type == 1)
                {
                    _loc_8[_loc_7] = new ItemData(lotteryDrawConst.diamondIDDic[_loc_2[_loc_7].value]);
                }
                _loc_7++;
            }
            this.eff.work(_loc_3, _loc_4, _loc_8);
            return;
        }// end function

        private function updateDiamondPool(event:Event) : void
        {
            this._diamondPoolBmpTxt.text = String(Cache.instance.lotteryDrawRecord.diamondPoolInfo.mainLotteryPool);
            this._test.text = String(Cache.instance.lotteryDrawRecord.diamondPoolInfo.deputyLotteryPool);
            return;
        }// end function

        private function updateMoney(param1:Object) : void
        {
            this._diamondNumTxt.htmlText = MoneyUtil.getFormatInt(Cache.instance.role.money.gold);
            return;
        }// end function

        private function onLotteryDrawTestPool(event:Event) : void
        {
            this._test.visible = Cache.instance.lotteryDraw.isShowTestPool;
            return;
        }// end function

        private function removeListener() : void
        {
            this._playBtn1.removeEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._playBtn2.removeEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._playBtn3.removeEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._modaiBtn.removeEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._rechargeBtn.removeEventListener(MouseEvent.CLICK, this.onClickHandle);
            Dispatcher.removeEventListener(EventName.LotteryDrawDiamondPoolUpdate, this.updateDiamondPool);
            NetDispatcher.removeCmdListener(ServerCommand.MoneyUpdate, this.updateMoney);
            Dispatcher.removeEventListener(EventName.LotteryDrawPackageBtnPlayEffect, this.onModaiEffectUpdate);
            Dispatcher.removeEventListener(EventName.LotteryDrawTestPool, this.onLotteryDrawTestPool);
            NetDispatcher.removeCmdListener(ServerCommand.NewDayUpdate, this.newDayUpdate);
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemsChange, this.onBagUpdate);
            return;
        }// end function

        private function newDayUpdate(param1:Object = null) : void
        {
            this.setItemShow();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.removeListener();
            var _loc_2:int = 0;
            while (_loc_2 < lotteryDrawConst.showItemNum)
            {
                
                this._showItemList[_loc_2].dispose(param1);
                this._showItemList[_loc_2] = null;
                _loc_2++;
            }
            this._specialBlock.dispose(param1);
            this._specialBlock = null;
            this._modaiBtn.dispose(param1);
            this._modaiBtn = null;
            this._rechargeBtn.dispose(param1);
            this._rechargeBtn = null;
            this._playBtn1.dispose(param1);
            this._playBtn1 = null;
            this._playBtn2.dispose(param1);
            this._playBtn2 = null;
            this._playBtn3.dispose(param1);
            this._playBtn3 = null;
            this._diamondPoolBmpTxt.dispose(param1);
            this._diamondPoolBmpTxt = null;
            this._costKeyTxt.dispose(param1);
            this._costKeyTxt = null;
            this._costKeyTxt1.dispose(param1);
            this._costKeyTxt1 = null;
            this._diamondNumTxt.dispose(param1);
            this._diamondNumTxt = null;
            this._keyTxt.dispose(param1);
            this._keyTxt = null;
            this._keyNumTxt.dispose(param1);
            this._keyNumTxt = null;
            this._diamondPoolItem.dispose(param1);
            this._diamondPoolItem = null;
            this._equipItem.dispose(param1);
            this._equipItem = null;
            this._skillItem.dispose(param1);
            this._skillItem = null;
            this._coinCumBox.dispose(param1);
            this._coinCumBox = null;
            this._level = -1;
            this._test.dispose();
            this._test = null;
            super.disposeImpl(param1);
            return;
        }// end function

    }
}
